<?php

/**
 * Framework_Object_DB
 *
 * @author      Joe Stump <joe@joestump.net>
 * @copyright   (c) 2006 Joseph C. Stump. All rights reserved.
 * @license http://www.opensource.org/licenses/bsd-license.php
 * @package Framework
 * @subpackage Object
 * @filesource
 */



/**
 * Framework_Object_DB
 *
 * Extends the base Framework_Object class to include a database connection. If
 * your class requires a database connection you will want to extend from this
 * class. 
 *
 * @author Joe Stump <joe@joestump.net>
 * @package Framework
 * @subpackage Object
 * @see Framework_Object
 */
abstract class Framework_Object_DB extends Framework_Object
{
    /**
     * $db
     *
     * @access protected
     * @var object $db Instance of PEAR DB connection
     * @see DB
     */
    public $db = null;

    /**
     * __construct
     *
     * @access public
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
        $this->db = Framework_DB::getDBConnection();
        
        if (PEAR::isError($this->db)) {
        	throw new Framework_Exception($this->db);
        }
    }

    /**
     * __sleep
     *
     * @access  public
     * @return  void
     */
    public function __sleep()
    {
        $this->db = null;
        parent::__sleep();
    }

    /**
     * __wakeup
     *
     * @access  public
     * @return  void
     */
    public function __wakeup()
    {
    	$this->db = Framework_DB::getDBConnection();
        parent::__wakeup();
    }

    /**
     * __destruct
     * 
     * @access public
     * @return void
     */
    public function __destruct()
    {
        parent::__destruct();
    }
}

?>
